
import SwiftUI
import GRDB

struct DuetInteractionsView: View {
    @State var rows = [Row]()
    let contactsMap: [Int:Row]

    var body: some View {
        List {
            ForEach(rows.reversed()) { row in
                NavigationLink(
                    destination: DuetInteractionView(row: row, senderRow: contactsMap[row["ZSENDER"] ?? Int.max]),
                    label: {
                        HStack {
                            let sender: Int = row["ZSENDER"] ?? Int.max
                            let senderRow = contactsMap[sender]
                            let senderText: String? = senderRow?["ZDISPLAYNAME"] ?? senderRow?["ZIDENTIFIER"]
                            let text = senderText ?? row["ZGROUPNAME"] ?? row["ZDOMAINIDNTIFIER"] ?? ""
                            Text(text)
                            Spacer()
                            Text(DateFormatter.formatter.string(from: Date(timeIntervalSinceReferenceDate: row["ZSTARTDATE"]!)))
                        }
                    })
            }
        }
    }
}
//
//struct DuetInteractionsView_Previews: PreviewProvider {
//    static var previews: some View {
//        DuetInteractionsView()
//    }
//}
